﻿using System;
using System.IO;
using System.Reflection;
using UnityEngine;

public class USSequencerUtility
{
    public static byte[] GetByteResource(string resourceName)
    {
        return GetByteResource(resourceName, null);
    }

    public static byte[] GetByteResource(string resourceName, Assembly assembly)
    {
        Stream resourceStream = GetResourceStream(resourceName, assembly);
        long length = 0L;
        if (resourceStream != null)
        {
            length = resourceStream.Length;
        }
        byte[] buffer = new byte[length];
        if (buffer.Length != 0)
        {
            resourceStream.Read(buffer, 0, (int) resourceStream.Length);
            resourceStream.Close();
        }
        return buffer;
    }

    public static Stream GetResourceStream(string resourceName)
    {
        return GetResourceStream(resourceName, null);
    }

    public static Stream GetResourceStream(string resourceName, Assembly assembly)
    {
        if (assembly == null)
        {
            assembly = Assembly.GetExecutingAssembly();
        }
        return assembly.GetManifestResourceStream(resourceName);
    }

    public static Texture2D GetTextureResource(string resourceName)
    {
        return GetTextureResource(resourceName, null);
    }

    public static Texture2D GetTextureResource(string resourceName, Assembly assembly)
    {
        Texture2D textured = new Texture2D(4, 4);
        textured.LoadImage(GetByteResource(resourceName, assembly));
        return textured;
    }

    public static bool HasObserverTimeline(Transform transform)
    {
        if (!IsTimelineContainer(transform))
        {
            return IsObserverTimeline(transform);
        }
        foreach (Transform transform2 in transform.GetComponentsInChildren<Transform>())
        {
            if (IsObserverTimeline(transform2))
            {
                return true;
            }
        }
        return false;
    }

    public static bool HasPropertyTimeline(Transform transform)
    {
        if (IsTimelineContainer(transform))
        {
            foreach (Transform transform2 in transform.GetComponentsInChildren<Transform>())
            {
                if (IsPropertyTimeline(transform2))
                {
                    return true;
                }
            }
        }
        return false;
    }

    public static bool IsEvent(Transform transform)
    {
        return (transform.GetComponent<USEventBase>() != null);
    }

    public static bool IsEventTimeline(Transform transform)
    {
        return (transform.GetComponent<USTimelineEvent>() != null);
    }

    public static bool IsObserverTimeline(Transform transform)
    {
        return (transform.GetComponent<USTimelineObserver>() != null);
    }

    public static bool IsPropertyTimeline(Transform transform)
    {
        return (transform.GetComponent<USTimelineProperty>() != null);
    }

    public static bool IsTimeline(Transform transform)
    {
        return (transform.GetComponent<USTimelineBase>() != null);
    }

    public static bool IsTimelineContainer(Transform transform)
    {
        return (transform.GetComponent<USTimelineContainer>() != null);
    }
}

